// 定义Bullet类
var Bullet=function (x1,y1,x2,y2,width,height) {
    this.width=width;
    this.height=height;
    this.x=x1;
    this.y=y1;
    this.angle=Math.atan2(y2-y1,x2-x1)
    this.speed=15;
    this.speedX=this.speed*Math.cos(this.angle);
    this.speedY=this.speed*Math.sin(this.angle);
    this.distance=400;
    this.oDiv=$('<div class="bullet"></div>');
    this.oDiv.css({
        'width':this.width,
        'height':this.height
    })
    document.getElementById('cqr').appendChild(this.oDiv.get(0));
};
Bullet.prototype.refreshPosition=function(that){
    this.x+=this.speedX;
    this.y+=this.speedY;
    this.distance-=this.speed;
    if(this.distance<=0){
        //document.getElementById('cqr').removeChild(this.oDiv.get(0));
        that.bullet.shift();//that为发射者 this为that的子弹
        return;
    }
    this.oDiv[0].style.top=this.y-this.width/2+'px';
    this.oDiv[0].style.left=this.x-this.width/2+'px'
};
Bullet.prototype.hitTest=function (object,j) {
    for(var i=0;i<object.length;i++){
        if(!object[i].death&&(i!=j)&&cirHitTest(object[i].x,object[i].y,object[i].width/2,this.x,this.y,this.width/2)){
            this.distance=0;
            object[i].beHit();
        }
    }
}